package com.homework.phase1.module3;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class InfoManagement {
    //集合用于存放学生信息
    List<Student> list = new LinkedList<>();

    Scanner sc = new Scanner(System.in);
    //添加学生
    public void addStudent() {

        System.out.println("请输入学号、姓名、年龄");

        String id = sc.next();
        String name = sc.next();
        int age = sc.nextInt();

        boolean b = list.add(new Student(id, name, age));

        if (b == true) {

            System.out.println("添加成功");
        } else {

            System.out.println("添加失败");
        }
    }

    //删除学生信息
    public void removeStudent() {
        System.out.println("请输入学号、姓名、年龄");
        String id = sc.next();
        String name = sc.next();
        int age = sc.nextInt();
        boolean b = list.remove(new Student(id, name ,age));

        if (b == true) {

            System.out.println("删除成功");
        } else {

            System.out.println("删除失败");
        }
    }
    //修改学生信息
    public void modifyStudent() {

        System.out.println("请输入学号、姓名、年龄");
        String id = sc.next();
        String name = sc.next();
        int age = sc.nextInt();


        if (list.contains(new Student(id, name, age))) {
            System.out.println("请要修改成的学号、姓名、年龄");
            String id1 = sc.next();
            String name1 = sc.next();
            int age1 = sc.nextInt();
            Student s = list.set(list.indexOf(new Student(id, name, age)),new Student(id1, name1 ,age1));
            System.out.println("修改成功");

        } else {
            System.out.println("查无此人");
        }

    }

    //查找学生信息
    public void findStudent() {
        System.out.println("请输入学号、姓名、年龄");
        String id = sc.next();
        String name = sc.next();
        int age = sc.nextInt();

        Student s = new Student(id, name, age);
        if (list.contains(s)) {

            System.out.println("已查找到此人");
            System.out.println("该学生信息为：" + s);


        } else {
            System.out.println("查无此人");
        }
    }
    //遍历学生信息
    public List<Student> allStudent(){

        return list;

    }
}
